package robot.differentialdrive;
import net.sf.json.JSONObject;


public class DifferentialDrive {
		private DifferentialDriveCommand command;
		private DifferentialDriveFeedback feedback;
		private DifferentialDriveProperties properties;
		private long timestamp;
		
		public DifferentialDrive(DifferentialDriveCommand command,
				DifferentialDriveFeedback feedback,
				DifferentialDriveProperties properties, long timestamp) {
			this.command = command;
			this.feedback = feedback;
			this.properties = properties;
			this.timestamp = timestamp;
		}

		public DifferentialDriveCommand getCommand() {
			return command;
		}

		public void setCommand(DifferentialDriveCommand command) {
			this.command = command;
		}

		public DifferentialDriveFeedback getFeedBack() {
			return feedback;
		}

		public void setFeedBack(DifferentialDriveFeedback feedback) {
			this.feedback = feedback;
		}

		public DifferentialDriveProperties getProperties() {
			return properties;
		}

		public void setProperties(DifferentialDriveProperties properties) {
			this.properties = properties;
		}

		public long getTimestamp() {
			return timestamp;
		}

		public void setTimestamp(long timestamp) {
			this.timestamp = timestamp;
		}
		
		/**
		 * Set differential drive from JSONObject
		 * @param obj the object containing values we want to store in differential drive objet
		 */
		public void setDifferentialDriveFromJSONObject(JSONObject obj){
			command.setTargetAngularSpeed(obj.getJSONObject("Command").getDouble("TargetAngularSpeed")); 
			command.setTargetLinearSpeed(obj.getJSONObject("Command").getDouble("TargetLinearSpeed"));
			feedback.setCurrentAngularSpeed(obj.getJSONObject("Feedback").getDouble("CurrentAngularSpeed"));
			feedback.setCurrentLinearSpeed(obj.getJSONObject("Feedback").getDouble("CurrentLinearSpeed"));
			feedback.setEnabled(obj.getJSONObject("Feedback").getBoolean("Enabled"));
			properties.setMaxAngularAcceleration(obj.getJSONObject("Properties").getInt("MaxAngularAcceleration"));
			properties.setMaxAngularSpeed(obj.getJSONObject("Properties").getInt("MaxAngularSpeed"));
			properties.setMinAngularSpeed(obj.getJSONObject("Properties").getInt("MinAngularSpeed"));
			properties.setMaxAngularDeceleration(obj.getJSONObject("Properties").getInt("MaxAngularDeceleration"));
			properties.setMaxLinearAcceleration(obj.getJSONObject("Properties").getInt("MaxLinearAcceleration"));
			properties.setMaxLinearDeceleration(obj.getJSONObject("Properties").getInt("MaxLinearDeceleration"));
			properties.setMaxLinearSpeed(obj.getJSONObject("Properties").getInt("MaxLinearSpeed"));
			properties.setMinLinearSpeed(obj.getJSONObject("Properties").getInt("MinLinearSpeed"));
			properties.setWidth(obj.getJSONObject("Properties").getInt("Width"));
		
		}
		
		
}
